Linq

[Solved] LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.

[Solved] LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression., someone asked me to explain?

This is caused because of Where-Expression.
You should only use variables in there or call methods that can be translated to SQL.

First, save your Session value in a variable:

int userId= (int)Session["UserId"];
posts = db.Posts.Where(a => a.UserId == userId)

Then use userId in your Where-Expression.

Post your comments / questions